package com.github.ghsea.sso.client.security.permission;

import javax.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * @author guhai
 */
@Component
public class PermissionManagerDelegate implements PermissionManager {

    @Resource(name = "PermissionManagerHttpImpl")
    private PermissionManager permissionManager;

    private PermissionManager customizePermissionManager;

    @Override
    public RolesAndPermissions getPermissions(String id, String mail) {
        if (customizePermissionManager != null) {
            return customizePermissionManager.getPermissions(id, mail);
        }

        return permissionManager.getPermissions(id, mail);
    }

    public PermissionManagerDelegate setCustomizePermissionManager(PermissionManager customizePermissionManager) {
        this.customizePermissionManager = customizePermissionManager;
        return this;
    }
}
